<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>采购订单相关的入库单记录</title>
    <script type="text/javascript">
      var newPurchaseOrderWin;
      var editPurchaseOrderWin;
      var purchaseOrderId;
      Ext.onReady(function(){
        var entryForPurchaseDS = new Ext.data.Store({
          baseParams:{id:'<%=params[:id]%>'},
          proxy: new Ext.data.HttpProxy({
            url: '/warehousing_entry/getWarehousingEntriesByPurchaseId'            
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'purchase_order_number',
              mapping:'purchase_order.order_number'
            },{
              name: 'order_number'
            }, {
              name: 'action_date'
            }, {
              name: 'description'
            }, {
              name: 'employee_name',
              mapping:'employee.name'
            },{
              name: 'department_name',
              mapping:'department.name'
            }, {
              name: 'warehouse_name',
              mapping:'warehouse.name'
            }, {
              name: 'vendor_name',
              mapping:'vendor.name'
            }, {
              name: 'auditing_status'
            }, {
              name: 'deal_with_status'
            }, {
              name: 'created_at'
            }, {
              name: 'updated_at'
            }])
        });

        //生成入库Grid的CM
        var entryForPurchaseSM = new Ext.grid.CheckboxSelectionModel({singleSelect:true});
        var entryForPurchaseCM = new Ext.grid.ColumnModel({defaults: {
            sortable: true,
            menuDisabled: false
          },columns:[new Ext.grid.RowNumberer(),entryForPurchaseSM,{
              id: 'common',
              header: 'DB',
              dataIndex: 'id',
              width: 50
            },{
              header: '采购单号',
              dataIndex: 'purchase_order_number',
              width: 130
            },{
              header: '入库单号',
              dataIndex: 'order_number',
              width: 110
            },{
              header: '供应商',
              dataIndex: 'vendor_name',
              width: 150
            },{
              header: '到仓库',
              dataIndex: 'warehouse_name',
              width: 80
            },{
              header: '入库日期',
              dataIndex: 'action_date',
              renderer: Ext.util.Format.dateRenderer('Y-m-d'),
              width: 75
            },{
              header: '操作员',
              dataIndex: 'employee_name',
              width: 60
            },{
              header: '部门',
              dataIndex: 'department_name',
              width: 70
            },{
              header: '审批状态',
              dataIndex: 'auditing_status',
              renderer: auditingStatusRender,
              width: 60
            },{
              header: '订单状态',
              dataIndex: 'deal_with_status',
              renderer: dealWithStatusRender,
              width: 60
            },{
              header: '生成日期',
              dataIndex: 'created_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
              width: 110
            },{
              header: '修改日期',
              dataIndex: 'updated_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
              width: 110
            }
          ]});

        //生成要订单的产品的Grid
        var entryForPurchaseGrid = new Ext.grid.GridPanel({
          title:'入库单列表',
          store: entryForPurchaseDS,
          cm: entryForPurchaseCM,
          sm: entryForPurchaseSM,
          loadMask: true,
          width: 980,
          height: 270,
          frame: true
        });
        entryForPurchaseDS.load();


        entryForPurchaseGrid.on('rowdblclick', function(gridPanel, rowIndex, e){
          entryId = entryForPurchaseDS.getAt(rowIndex).get('id');
          var purchaseOrderNumber = entryForPurchaseDS.getAt(rowIndex).get('order_number');
          //entryForPurchaseDS.reload();
          warehousingEntryDetailDS.removeAll();
          warehousingEntryDetailDS.baseParams.id = entryId;
          warehousingEntryDetailDS.load();
          warehousingEntryDetailGrid.setTitle("入库单："+purchaseOrderNumber+"，的详细信息");
        });

        //--------------------------入库单详细，双击后可显示数据----------------
        var warehousingEntryDetailDS = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: '/warehousing_entry/getWarehousingEntryDetailsById'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'product_name',
              mapping:'product.name'
            },{
              name: 'product_number',
              mapping:'product.number'
            },{
              name: 'product_spec',
              mapping:'product.spec'
            },{
              name: 'quantity'
            }, {
              name: 'unit_price'
            }, {
              name: 'amount'
            }, {
              name: 'is_suit',
              mapping:'product.is_suit',
              convert:function(value,record){
                if(value == "1"){
                  return "套装";
                }else if(value == "0"){
                  return "单品";
                }
              }
            }, {
              name: 'description'
            }])
        });

        //生成采购订单详细表的Grid的CM
        var warehousingEntryDetailSM = new Ext.grid.CheckboxSelectionModel({singleSelect:true});
        var warehousingEntryDetailCM = new Ext.grid.ColumnModel({defaults: {
            sortable: true,
            menuDisabled: false
          },columns:[new Ext.grid.RowNumberer(),warehousingEntryDetailSM,{
              id: 'common',
              header: 'DB',
              dataIndex: 'id',
              width: 50
            },{
              header: '产品名称',
              dataIndex: 'product_name',
              width: 200
            },{
              header: '编号',
              dataIndex: 'product_number',
              width: 70
            },{
              header: '规格',
              dataIndex: 'product_spec',
              width: 80
            },{
              header: '数量',
              dataIndex: 'quantity',
              align: 'right',
              width: 80
            },{
              header: '单价',
              dataIndex: 'unit_price',
              renderer: Ext.util.Format.numberRenderer('0,000.00'),
              align: 'right',
              width: 70
            },{
              header: '总价',
              dataIndex: 'amount',
              align: 'right',
              renderer: Ext.util.Format.numberRenderer('0,000.00'),
              width: 80
            },{
              header: '套装或单品',
              dataIndex: 'is_suit',
              width: 70
            },{
              header: '备注',
              dataIndex: 'description',
              width: 150
            }
          ]});
        //生成要订单的产品的Grid
        var warehousingEntryDetailGrid = new Ext.grid.GridPanel({
          title:'入库单详细列表',
          store: warehousingEntryDetailDS,
          cm: warehousingEntryDetailCM,
          sm: warehousingEntryDetailSM,
          loadMask: true,
          width: 980,
          height: 270,
          frame: true
          //title: '进货品种列表',
          //plain:true,
          //plugins: checkColumn,
        });
        //总的panel
        var workbenchPanel = new Ext.Panel({
          width: 990,
          height: 590,
          frame:false,
          layout:'table',
          layoutConfig: {columns:1},
          defaults:{margins:'5 5 5 5'},
          items:[entryForPurchaseGrid,warehousingEntryDetailGrid]
        });
        workbenchPanel.render("entry_for_purchase_workbench_panel");
      })
    </script>
  </head>
  <body>
    <div id="entry_for_purchase_workbench_panel"></div>
  </body>
</html>